-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Fix bug and add test case #2168
Conversation
WalkthroughWalkthroughThe changes introduce enhancements to the testing framework, including a new test configuration for scenarios with inactive validators, a function to retrieve additional validator configurations, and the simulation of validator actions within a blockchain context. These modifications aim to improve the robustness and flexibility of the e2e testing suite, particularly concerning top N validator scenarios. Changes
Assessment against linked issues
Recent review detailsConfiguration used: .coderabbit.yml Files selected for processing (2)
Files skipped from review as they are similar to previous changes (2)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Outside diff range, codebase verification and nitpick comments (1)
testutil/keeper/unit_test_helpers.go (1)
225-225
: Mismatch in function signature and call.The function
SetupMocksForLastBondedValidatorsExpectation
is defined with four parameters, but the call in the test file uses only three arguments. This discrepancy needs to be addressed to ensure consistency between the function definition and its usage.
- Function Definition:
testutil/keeper/expectations.go
, line 223- Function Call:
testutil/keeper/unit_test_helpers.go
, line 225Analysis chain
Verify the function signature update.
Ensure that the
SetupMocksForLastBondedValidatorsExpectation
function signature has been updated to reflect this change in parameters.Run the following script to verify the function signature:
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the function signature of `SetupMocksForLastBondedValidatorsExpectation`. # Test: Search for the function definition. Expect: Updated signature with a single integer argument. ast-grep --lang go --pattern 'func SetupMocksForLastBondedValidatorsExpectation($_, $_, $_, $_)'Length of output: 1049
x/ccv/types/utils.go
Outdated
// get the bonded validators from the staking module, sorted by power | ||
bondedValidators, err := stakingKeeper.GetBondedValidatorsByPower(ctx) | ||
if err != nil { | ||
return nil, err | ||
panic(fmt.Errorf("failed to get bonded validators: %w", err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using panic for error handling.
Using panic
for error handling can cause a chain halt. Consider returning an error instead to handle failures gracefully.
Apply this diff to replace the panic with error handling:
if err != nil {
- panic(fmt.Errorf("failed to get bonded validators: %w", err))
+ return nil, fmt.Errorf("failed to get bonded validators: %w", err)
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
// get the bonded validators from the staking module, sorted by power | |
bondedValidators, err := stakingKeeper.GetBondedValidatorsByPower(ctx) | |
if err != nil { | |
return nil, err | |
panic(fmt.Errorf("failed to get bonded validators: %w", err)) | |
// get the bonded validators from the staking module, sorted by power | |
bondedValidators, err := stakingKeeper.GetBondedValidatorsByPower(ctx) | |
if err != nil { | |
return nil, fmt.Errorf("failed to get bonded validators: %w", err) |
Tools
GitHub Check: CodeQL
[warning] 135-135: Panic in BeginBock or EndBlock consensus methods
Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving the change, I have no objections to testing changes.
return i >= int(maxVals) // stop iteration if true | ||
}) | ||
// get the bonded validators from the staking module, sorted by power | ||
bondedValidators, err := stakingKeeper.GetBondedValidatorsByPower(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was super subtle. Great catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @p-offtermatt
Description
Closes: #2169
Bug reported by @fastfadingviolets via Slack
In the test scenario presented in the new e2e test, namely:
The previous behaviour was that validator 10 did not have to validate, and only 30, 29, and 20 had to validate.
The bug was this:
In
interchain-security/x/ccv/types/utils.go
Line 134 in 0e080c3
This is not true, so wrong validators would be returned, which caused wrong validators to be used when computing the consumer chain validator set.
The fix is in x/ccv/types/utils.go
tests/e2e contains a regression tests outlining the scenario explained above.
In the integration tests, a test actually depended on the broken behaviour, so it was adjusted.
Further, the mocks were adjusted, since GetLastBondedValidatorsUtil calls GetBondedValidatorsByPower instead of IterateLastValidatorPowers now, and doesn't need to take the powers as an input.
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if the change is state-machine breakingCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
the type prefix if the change is state-machine breakingSummary by CodeRabbit
New Features
Bug Fixes
Refactor
Tests